# this script conpiles information about all the data in a frequency directory and makes some plots

import cPickle
import os
from numpy import *
from dendritetics_classes import *
import copy


# list directories that have -Hz in their names
for directory in os.listdir('../../data'):
    if directory.find('-Hz') != -1:
        print directory

freq =  raw_input("Enter the frequency you'd like to compile information on: ")

# get all the cells from thier pickles
cells = []
listing = os.listdir('../../data/' + freq + '-Hz')
for dir in copy.deepcopy(listing):
    if "generation" in dir:
        listing.remove(dir)
print str(listing)

one_percent = len(listing)/100
# make sure the number of cells is odd
if one_percent % 2 == 0:
    one_percent += 1

for directory in listing[-one_percent:]:
    cells.append( cPickle.load(open('../../data/' + freq + '-Hz/' + directory + '/cell.cPickle')) )
num_cells = len(cells)

print "There are %d cells in this directory.  %d cells make up the top 1 percent." % (num_cells,one_percent)

scores = []
for cell in cells:
    scores.append(cell.score)

# make a population object and add these cells to it
cpop = Cpopulation()
cpop.cells = cells
cpop.scores = scores
cpop.avg_scores.append(sum(scores)/len(scores))
print "Evolving the original top ten percent of cells"
for i in range(len(cpop.cells)):
    print "     ---> cell %d had a score of %f" % (i,cpop.cells[i].score)
cpop.evolve()
cpop.exercise()
cpop.evolve()
cpop.exercise()
cpop.evolve()
cpop.exercise()
cpop.evolve()
cpop.exercise()
cpop.evolve()
cpop.exercise()
cpop.evolve()
cpop.exercise()
cpop.evolve()
cpop.exercise()

    
